package 力扣日常刷题.木22二月.第14天220;

import java.util.Stack;

/**
 * @author 帅小伙
 * @date 2022/2/20
 * @description
 */
public class Demo125栈的弹出压入序列 {


    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack = new Stack<>();
        int index = 0;
        for (int i : pushed) {
            stack.push(i);
            while (!stack.isEmpty() && stack.peek() == popped[index]) {
                stack.pop();
                index++;
            }
        }
        return stack.isEmpty();
    }
}
